// D0 = GPIO16;
// D1 = GPIO5;
// D2 = GPIO4;
// D3 = GPIO0;can not download when connected to low
// D4 = GPIO2;  LED on esp8266
// D5 = GPIO14;
// D6 = GPIO12;
// D7 = GPIO13;
// D8 = GPIO15;  can not start when high input
// D9 = GPIO3; UART RX
// D10 = GPIO1; UART TX
// LED_BUILTIN = GPIO16 (auxiliary constant for the board LED, not a board pin);

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <ArduinoJson.h>
#include <Ticker.h>
#include "Button2.h"

Button2 buttonA, buttonB, buttonC, buttonD;

#include "time.h"
#define timezone 8

#define DEVICE_NAME "ESP_LIGHT" // 设备名

#define LIGHT_NUMBER 4 // 节点开关数量

#define LIGHT_1_PIN 5
#define LIGHT_2_PIN 4
#define LIGHT_3_PIN 2
#define LIGHT_3B_PIN 16
#define LIGHT_4_PIN 14
#define LIGHT_4B_PIN 12

#define CONTROL_1_PIN 13
#define CONTROL_2_PIN 1
#define CONTROL_3_PIN 0
#define CONTROL_4_PIN 3

unsigned char RelayPin[LIGHT_NUMBER];  // = {RELAY1,RELAY2};
unsigned char RelayPin2[LIGHT_NUMBER]; // 磁保持继电器的B pin

unsigned char CONTROL_PIN[LIGHT_NUMBER]; // 按键开关pin

bool touch_touched[LIGHT_NUMBER] = {}; // 单击判断，作为灯开关的动作判断

bool CONTROL_STAT[LIGHT_NUMBER] = {1, 1, 1, 1};

String
    apSSID = "";


Ticker ticker1s;

#define BLINKER_WIFI
#define BLINKER_ALIGENIE_MULTI_OUTLET   //天猫精灵多通道
#define BLINKER_MIOT_MULTI_OUTLET   //小米米家
#define BLINKER_WITHOUT_SSL
// #define BLINKER_ESP_SMARTCONFIG
#include <Blinker.h>

#define BUTTON_1 "btn-light1"
#define BUTTON_2 "btn-light2"
#define BUTTON_3 "btn-light3"
#define BUTTON_4 "btn-light4"
BlinkerButton BButton1(BUTTON_1);
BlinkerButton BButton2(BUTTON_2);
BlinkerButton BButton3(BUTTON_3);
BlinkerButton BButton4(BUTTON_4);

const char *blinker_id = ""; //...点灯注册设备号

// 一定要修改这里，使用自己的wifi信息
const char *ServerName = "ESP-Light";

// 配置json
DynamicJsonDocument config_json(1024);
// 恢复默认配置
void loadDefaultConfig()
{
    Serial.println("loadDefaultConfig\n");

    // 网络配置
    config_json["STA_ssid"] = "ssid";
    config_json["STA_passwd"] = "passwd";
}